package read

import (
	"cloud-entropy-storage-system/common/pkg/pathdir"
	"fmt"
	"io"
	"mime/multipart"
)

func ByMultipart(f multipart.File, size int) (string, []byte) {
	var data []byte
	buf := make([]byte, 1024*1024)
	for {
		n, err := f.Read(buf)
		if err != nil && err != io.EOF {
			fmt.Println(err)
			return "", nil
		}
		if n == 0 {
			break
		}
		data = append(data, buf[:n]...)
	}
	if len(data) != size {
		fmt.Println("读取字节数与预期不符")
		return "", nil
	}
	md := pathdir.GetMdByte(data)
	return md, data
}
